package wortubung.core;
/**
 * An example string follow these conventions:
 *   ~ represent the original as a whole;
 *   &gt;...&lt; represents the conjugated form.
 *   For idioms, &gt;...&lt; also represent its parts when they are separeted.
 *   [...] quotes the explanation, which goes last always.
 */
public class EXAMPLE {
    private String example;
    private String explanation;
	private transient boolean needReplace;

    public EXAMPLE(String sample) {
        int idx = sample.lastIndexOf("[");
        if (idx > 0) {
            example = sample.substring(0, idx).trim();
            explanation = sample.substring(idx+1).trim();
            if (explanation.endsWith("]"))
                explanation = explanation.substring(0, explanation.length()-1).trim();
        } else {
            example = sample;
        }
		this.needReplace = example.contains("<");
    }

    public String getExample() { return example; }
    public String getExplanation() { return explanation; }
    public String getExampleDisplay() {
    	if (needReplace)
    		return example.replaceAll("<", "").replaceAll(">", "");
    	return example;
	}
}
